﻿#region Header
// Copyright 2007-2011, Jerónimo Milea
// 
// This file is part of NetJsWire.
// 
//     NetJsWire is free software: you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
// 
//     NetJsWire is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
// 
//     You should have received a copy of the GNU General Public License
//     along with NetJsWire.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace NetJsWire.Widgets.Core
{
    [ProvideProperty( "ToolTip", typeof( Control ) )]
    public class ToolTip : Component, IExtenderProvider
    {
        readonly Hashtable _toolTips = new Hashtable();
        
        public ToolTip()
        {
        }

        public ToolTip( IContainer container )
        {
            container.Add( this );
        }

        public void SetToolTip( Control widget, string value )
        {
            if ( !string.IsNullOrWhiteSpace( value ) )
                _toolTips[ widget ] = value;
            else
                _toolTips.Remove( widget );
        }

        public string GetToolTip( Control widget )
        {
            if ( _toolTips.ContainsKey( widget ) )
                return ( string ) _toolTips[ widget ];

            return string.Empty;
        }

        #region Implementation of IExtenderProvider

        /// <summary>
        ///   La colección de widgets con ToolTip
        /// </summary>
        public Hashtable Widgets { get { return _toolTips; } }

        /// <summary>
        ///   Especifica si este objeto puede proporcionar las propiedades Extender al objeto especificado.
        /// </summary>
        /// <returns>
        ///   Es true si este objeto puede proporcionar propiedades extensoras al objeto especificado; en caso contrario, es false.
        /// </returns>
        /// <param name = "extendee"><see cref = "T:System.Object" /> para recibir las propiedades Extender. </param>
        public bool CanExtend( object extendee )
        {
            return extendee is Control;
        }

        #endregion
    }
}
